package com.zy.design.pattern.factory.simple;

import com.zy.design.pattern.factory.base.IRuleConfigParser;
import com.zy.design.pattern.factory.base.JsonRuleConfigParser;
import com.zy.design.pattern.factory.base.YamlRuleConfigParser;

/**
 * @author zhaoyi
 * @date 2021/3/29 17:58
 */
public class ConfigParserFactory {

    public static IRuleConfigParser createParser(String configFormat) {
        IRuleConfigParser parser = null;
        if ("json".equalsIgnoreCase(configFormat)) {
            parser = new JsonRuleConfigParser();
        } else if ("yaml".equalsIgnoreCase(configFormat)) {
            parser = new YamlRuleConfigParser();
        } else {
            String msg = String.format("无对应解析器 %s", configFormat);
            throw new IllegalArgumentException(msg);
        }
        return parser;
    }


}
